package com.tansun.easycare.rule.common.symbol;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.tansun.easycare.rule.common.model.BaseBean;

/**
 * 生成 锚点和值的数据
 *
 * @author WY
 */
public class WidgetCreator {

    public static String initAnchor() {
        Map<String, Anchor> map = getAnchorMap();
        return JSON.toJSONString(map);

    }

    public static String initDrlConsValue() {
        Map<String, DrlValue> map = getDrlValueMap();
        return JSON.toJSONString(map);
    }

    private static Map<String, DrlValue> drlValueMap = new HashMap<String, DrlValue>();
    private static Map<String, Anchor> anchorMap = new HashMap<String, Anchor>();

    /**
     * 锚点对象 4类
     */
    public static Map<String, Anchor> getAnchorMap() {
        if (anchorMap.size() > 0) {
            return anchorMap;
        } else {

            Anchor anchor_setvar = new Anchor();
            anchor_setvar.setId("");
            anchor_setvar.setLabel("");
            anchor_setvar.setName("anchor");
            anchor_setvar.setType(BaseBean.TYPE_ANCHOR);
            anchor_setvar.setAnType("anchor_setvar");
            anchorMap.put("anchor_setvar", anchor_setvar);

            Anchor anchor_condition = new Anchor();
            anchor_condition.setId("");
            anchor_condition.setLabel("");
            anchor_condition.setName("anchor");
            anchor_condition.setType(BaseBean.TYPE_ANCHOR);
            anchor_condition.setAnType("anchor_condition");
            anchorMap.put("anchor_condition", anchor_condition);

            Anchor anchor_action = new Anchor();
            anchor_action.setId("");
            anchor_action.setLabel("");
            anchor_action.setName("anchor");
            anchor_action.setType(BaseBean.TYPE_ANCHOR);
            anchor_action.setAnType("anchor_action");
            anchorMap.put("anchor_action", anchor_action);

            Anchor anchor_common = new Anchor();
            anchor_common.setId("");
            anchor_common.setLabel("");
            anchor_common.setName("anchor");
            anchor_common.setType(BaseBean.TYPE_ANCHOR);
            anchor_common.setAnType("anchor_common");
            anchorMap.put("anchor_common", anchor_common);

            return anchorMap;
        }
    }

    /**
     * 值
     */
    public static Map<String, DrlValue> getDrlValueMap() {
        //drools.getRule().getAgendaGroup()+":"+drools.getRule().getName()
        if (drlValueMap.size() > 0) {
            return drlValueMap;
        } else {
            DrlValue drlLong = new DrlValue();
            drlLong.setId("hdlong9T");
            drlLong.setLabel("整型值");
            drlLong.setName("drlLong");
            drlLong.setType(BaseBean.TYPE_VALUE);
            drlLong.setDataType("Long");
            drlValueMap.put("drlLong", drlLong);

            DrlValue drlDouble = new DrlValue();
            drlDouble.setId("hddoub9T");
            drlDouble.setLabel("实型值");
            drlDouble.setName("drlDouble");
            drlDouble.setType(BaseBean.TYPE_VALUE);
            drlDouble.setDataType("Double");
            drlValueMap.put("drlDouble", drlDouble);

            DrlValue drlDate = new DrlValue();
            drlDate.setId("hddate9T");
            drlDate.setLabel("日期值");
            drlDate.setName("drlDate");
            drlDate.setType(BaseBean.TYPE_VALUE);
            drlDate.setDataType("Date");
            drlValueMap.put("drlDate", drlDate);

            DrlValue drlCurrDate = new DrlValue();
            drlCurrDate.setId("hdcure9T");
            drlCurrDate.setLabel("当前日期");
            drlCurrDate.setName("drlCurrDate");
            drlCurrDate.setType(BaseBean.TYPE_VALUE);
            drlCurrDate.setDataType("Date");
            drlValueMap.put("drlCurrDate", drlCurrDate);

            DrlValue drlString = new DrlValue();
            drlString.setId("hdstre9T");
            drlString.setLabel("字符值");
            drlString.setName("drlString");
            drlString.setType(BaseBean.TYPE_VALUE);
            drlString.setDataType("String");
            drlValueMap.put("drlString", drlString);


            DrlValue drlBoolean = new DrlValue();
            drlBoolean.setId("hdbwws9T");
            drlBoolean.setLabel("布尔");
            drlBoolean.setName("drlBoolean");
            drlBoolean.setType(BaseBean.TYPE_VALUE);
            drlBoolean.setDataType("Boolean");
            drlValueMap.put("drlBoolean", drlBoolean);

            DrlValue agendaGroup = new DrlValue();
            agendaGroup.setId("hd8rfs9T");
            agendaGroup.setLabel("规则集名");
            agendaGroup.setName("ruleGroup");
            agendaGroup.setType(BaseBean.TYPE_VALUE);
            agendaGroup.setDataType("String");
            agendaGroup.setValue("drools.getRule().getAgendaGroup() ");
            drlValueMap.put("agendaGroup", agendaGroup);

            DrlValue ruleName = new DrlValue();
            ruleName.setId("asdjf9lE");
            ruleName.setLabel("规则名");
            ruleName.setName("ruleName");
            ruleName.setType(BaseBean.TYPE_VALUE);
            ruleName.setDataType("String");
            ruleName.setValue("drools.getRule().getName() ");
            drlValueMap.put("ruleName", ruleName);

            DrlValue drlNull = new DrlValue();
            drlNull.setId("Esd3k9lE");
            drlNull.setLabel("空值");
            drlNull.setName("drlNull");
            drlNull.setType(BaseBean.TYPE_VALUE);
            drlNull.setDataType("Map");
            drlNull.setValue(" null ");
            drlValueMap.put("drlNull", drlNull);

            return drlValueMap;
        }

    }

    public static void main(String[] args) {
        System.out.println(initAnchor());
        System.out.println(initDrlConsValue());
    }
}
